package com.lock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/2/26  9:56
 * 描述:
 */
public class TestLockRunable implements Runnable {

    private ReentrantLock reentrantLock;

    public TestLockRunable(ReentrantLock reentrantLock) {
        this.reentrantLock = reentrantLock;
    }

    @Override
    public void run() {

        reentrantLock.lock();
       try{

           for(int i=0;i<5;i++) {
               Thread.sleep(1000);
               System.out.println(Thread.currentThread().getName() + "==>" + i);
           }
       }catch (Exception e){
           e.printStackTrace();
       }finally {
           reentrantLock.unlock();
       }



    }
}
